package com.ssy.lingxi.platform.manage.controller;

import com.ssy.lingxi.common.constant.manage.ShopEnvironmentEnum;
import com.ssy.lingxi.common.constant.manage.ShopPropertyEnum;
import com.ssy.lingxi.common.constant.manage.ShopTypeEnum;
import com.ssy.lingxi.platform.manage.constant.ColumnTypeEnum;
import com.ssy.lingxi.platform.manage.constant.CommonBooleanEnum;
import com.ssy.lingxi.platform.manage.constant.RecommendLabelEnum;
import com.ssy.lingxi.platform.manage.constant.ShelfEnum;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

/**
 * @author lqa
 * @version 2.0.0
 * @date 2022/2/15
 */
@RestController
@RequestMapping("/manage/test")
public class TestController {

    @RequestMapping("/test1")
    public void test1() {
        ShopEnvironmentEnum[] values = ShopEnvironmentEnum.values();
        for (ShopEnvironmentEnum value : values) {
            String message = value.getMessage();
            System.out.println(message);
        }
        System.out.println(ShopEnvironmentEnum.getMessage(1));

    }

    @RequestMapping("/test")
    public String test() throws IOException {
        String filepath = "d:/messages.properties";


        List<String> content = new ArrayList<>();
        for (ColumnTypeEnum value : ColumnTypeEnum.values()) {
            String key = value.getClass().getName();
            content.add(key.substring(key.lastIndexOf(".") + 1).concat(".").concat(String.valueOf(value.getCode())).concat("=").concat(value.getMessage()));
        }

  content.add("");

        for (CommonBooleanEnum value : CommonBooleanEnum.values()) {
            String key = value.getClass().getName();
            content.add(key.substring(key.lastIndexOf(".") + 1).concat(".").concat(String.valueOf(value.getCode())).concat("=").concat(value.getMessage()));
        }

        content.add("");

        for (RecommendLabelEnum value : RecommendLabelEnum.values()) {
            String key = value.getClass().getName();
            content.add(key.substring(key.lastIndexOf(".") + 1).concat(".").concat(String.valueOf(value.getCode())).concat("=").concat(value.getMessage()));
        }

        content.add("");

        for (ShelfEnum value : ShelfEnum.values()) {
            String key = value.getClass().getName();
            content.add(key.substring(key.lastIndexOf(".") + 1).concat(".").concat(String.valueOf(value.getCode())).concat("=").concat(value.getMessage()));
        }

        content.add("");

              for (ShopEnvironmentEnum value : ShopEnvironmentEnum.values()) {
            String key = value.getClass().getName();
            content.add(key.substring(key.lastIndexOf(".") + 1).concat(".").concat(String.valueOf(value.getCode())).concat("=").concat(value.getMessage()));
        }

        content.add("");

        for (ShopPropertyEnum value : ShopPropertyEnum.values()) {
            String key = value.getClass().getName();
            content.add(key.substring(key.lastIndexOf(".") + 1).concat(".").concat(String.valueOf(value.getCode())).concat("=").concat(value.getName()));
        }

        content.add("");

        for (ShopTypeEnum value : ShopTypeEnum.values()) {
            String key = value.getClass().getName();
            content.add(key.substring(key.lastIndexOf(".") + 1).concat(".").concat(String.valueOf(value.getCode())).concat("=").concat(value.getName()));
        }


        Files.write(Paths.get(filepath), content, StandardCharsets.UTF_8);
        return "ok";
    }
}
